package com.example.admin.yuejian21.fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.admin.yuejian21.Adapter.CourseAdapter;
import com.example.admin.yuejian21.Bean.Club;
import com.example.admin.yuejian21.Bean.Course;
<<<<<<< HEAD
=======
import com.example.admin.yuejian21.Bean.CourseA;
import com.example.admin.yuejian21.Bean.VideoList;
import com.example.admin.yuejian21.Model.MasterModel;
>>>>>>> 2e6d2ff2e3331c5e86ecd66212336d2d1a6d7e80
import com.example.admin.yuejian21.R;
import com.example.admin.yuejian21.Service.Service;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static com.example.admin.yuejian21.Adapter.RenqiAdapter.id;

/**
 * A simple {@link Fragment} subclass.
 */
public class CourseFragment extends Fragment {

    private RecyclerView recyclerView;
<<<<<<< HEAD

    private CourseAdapter adapter;
    List<Course> Courselist;
    private String SessionID="060pn7sjorpnq5fp53kid5st54";
    public CourseFragment() {
        // Required empty public constructor
    }
    public void onViewCreated(View view,  @Nullable Bundle savedInstanceState) {

        recyclerView =
                (RecyclerView) view.findViewById(R.id.recyclerView);
        Retrofit retrofit = new Retrofit.Builder().baseUrl("http://172.24.10.175/workout/api.php/").addConverterFactory(GsonConverterFactory.create())
                .build();
        Service service = retrofit.create(Service.class);
        Call<Club> call = service.Course(SessionID,id);
        call.enqueue(new Callback<Club>() {
            @Override
            public void onResponse(Call<Club> call, Response<Club> response) {
                if (getActivity() != null) {
                Courselist = response.body().getClubcourse();
                   ;
                    if(Courselist!=null)
                    {  adapter = new CourseAdapter(getActivity(), Courselist);
                    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
                    linearLayoutManager.setOrientation(linearLayoutManager.VERTICAL);
                    recyclerView.setLayoutManager(linearLayoutManager);
                    recyclerView.setAdapter(adapter);
                    recyclerView.setItemAnimator(new DefaultItemAnimator());}
                }

            }

            public void onFailure(Call<Club> call, Throwable t) {
=======
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        View view = inflater.inflate(R.layout.fragment_course,container,false);
        recyclerView = (RecyclerView) view.findViewById(R.id.course_rv);
        recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity()));//设置布局
        showData();
        return view;
    }
    private void showData(){
        String dashi_id=getActivity().getIntent().getStringExtra("dashi_id");
        MasterModel masterModel = new MasterModel();
        Call<VideoList> call = masterModel.getVideoList(dashi_id,"mvideo");
        call.enqueue(new Callback<VideoList>() {
            @Override
            public void onResponse(Call<VideoList> call, Response<VideoList> response) {
                VideoList mDataList = response.body();
                List<VideoList.MvideoBean> vlist=mDataList.getMvideo();
                recyclerView.setAdapter(new CourseAdapter(CourseFragment.this.getContext(),vlist));//设置适配器，绑定Adapter.
            }

            @Override
            public void onFailure(Call<VideoList> call, Throwable t) {
>>>>>>> 2e6d2ff2e3331c5e86ecd66212336d2d1a6d7e80

            }
        });
    }
}